﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EZCRS.HCMS.DataAcl;
using dotnetCHARTING;
using System.Drawing;
using EZCRS.HCMS.Web;

namespace EZCRS.HCMS.Web.manage.booklog
{
    public partial class reportall : ManageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                rbltype.DataSource = DataAcl.Common.CakyYearClass();
                rbltype.DataTextField = "value";
                rbltype.DataValueField = "key";
                rbltype.DataBind();
                rbltype.SelectedValue = "1";

                ddlyear.SelectedValue = DateTime.Now.Year.ToString();
                ddlmonth.SelectedValue = DateTime.Now.Month.ToString();

                switch (DataAcl.CFun.RequestString("reporttype"))
                {
                    case "checkin"://入住
                        CheckModule(50);
                        Literal1.Text = "<a href=\"orderstatusall.aspx\">" + Resources.Site.Detail + ">>></a>";
                        Titlepage1.inittitle = Resources.Site.checkinAll;
                        break;
                    case "noshow"://noshow
                        CheckModule(51);
                        Literal1.Text = "<a href=\"noshowall.aspx\">" + Resources.Site.Detail + ">>></a>";
                        Titlepage1.inittitle = Resources.Site.NoShowRecordAll;
                        break;
                    case "booking"://noshow
                        CheckModule(49);
                        Literal1.Text = "<a href=\"bookrecordall.aspx\">" + Resources.Site.Detail + ">>></a>";
                        break;
                    default://预定
                        CheckModule(49);
                        Literal1.Text = "<a href=\"bookrecordall.aspx\">" + Resources.Site.Detail + ">>></a>";
                        break;
                }

                try
                {
                    createchart();
                }
                catch
                {
                    errlab.InnerHtml = DataAcl.Common.charterrormsg;
                }
            }
        }

        private void createchart()
        {
            #region
            string daytime = ddlyear.SelectedValue;
            if (rbltype.SelectedValue == "1")
                daytime += "-" + ddlmonth.SelectedValue;
            string titles = Resources.Site.BookRecordAll;
            string reporttype = DataAcl.CFun.RequestString("reporttype");
            if (reporttype == "")
                reporttype = "booking";
            switch (DataAcl.CFun.RequestString("reporttype"))
            {
                case "checkin"://入住
                    titles = Resources.Site.checkinAll;
                    break;
                case "noshow"://noshow
                    titles = Resources.Site.NoShowRecordAll;
                    break;
                default://预定
                    break;
            }
            string daytype = rbltype.SelectedValue;// 统计时间类型
            string titleday = Resources.Site.Year, titleitem = Resources.Site.Month;
            int total = 12;
            if (daytype == "1")
            {
                total = 31;
                titleday = Resources.Site.Month;
                titleitem = Resources.Site.Day;
            }


            // Set the title.
            Chart.Title = titles + Resources.Site.Analysis;

            // Set the Depth
            Chart.Depth = 15;

            // Set 3D
            Chart.Use3D = true;

            // set the x axis clustering
            Chart.XAxis.ClusterColumns = false;

            // Set a default transparency
            Chart.DefaultSeries.DefaultElement.Transparency = 20;

            // Set a default line Width
            Chart.DefaultSeries.Line.Width = 30;

            // Set the y Axis Scale
            Chart.YAxis.Scale = Scale.Normal;

            // Set the x axis label
            //Chart.XAxis.Label.Text = "日";

            // Set the y axis label
            Chart.YAxis.Label.Text = titles + Resources.Site.Number;

            // Set the directory where the images will be stored.
            Chart.TempDirectory = "../../temp";


            // Set he chart size.
            Chart.Width = 800;
            Chart.Height = 350;

            #region
            //string strSql = "SELECT     COUNT(*) AS counts, DATEPART(dd, indate) AS dd  FROM         hfg_bookview WHERE     (CONVERT(char(7), indate, 20) = '2008-05') GROUP BY DATEPART(dd, indate)";
            DataTable dtInfo = new OrderInfo().userreport(reporttype, daytype, daytime, BasGroupId, BasHotelId, 1);

            SeriesCollection SC = new SeriesCollection();
            //Random myR = new Random();

            Series s = new Series();
            s.Name = titleday + titles;

            for (int b = 1; b <= total; b++)
            {
                Element e1 = new Element();

                e1.Name = b + titleitem;

                e1.YValue = 0;

                //e2.YValue = 0;
                foreach (DataRow dr in dtInfo.Rows)
                {
                    //Response.Write(i.ToString());
                    if (dr["ditem"].ToString() == b.ToString())
                        e1.YValue = Convert.ToDouble(dr["counts"].ToString());
                }


                s.Elements.Add(e1);
                SC.Add(s);
            }





            // Set Different Colors for our Series
            SC[0].DefaultElement.Color = Color.FromArgb(49, 255, 49);


            // Set 2 series to bars and 2 to lines.
            SC[0].Type = SeriesType.Column;

            #endregion
            // Add the random data.
            Chart.SeriesCollection.Add(SC);
            #endregion
        }

        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                createchart();
            }
            catch 
            {
                errlab.InnerHtml = DataAcl.Common.charterrormsg;
            }
        }
    }
}
